package com.dede.baselib;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.dede.baselib.state.StateActivity;
import com.dede.rxbase.dialog.StateDialog;

import java.util.ArrayList;

import kotlin.Unit;
import kotlin.jvm.functions.Function2;

public class MainActivity extends BaseActivity {

    @Nullable
    @Override
    protected View createTitle() {
        final View view = new View(this);
        view.setBackgroundColor(Color.RED);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "title", Toast.LENGTH_SHORT).show();
            }
        });
        view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 150));
        return view;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
//        BarUtils.immerseStatusBar(this);
        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < 18; i++) {
            strings.add(String.valueOf(i));
        }
        PagerList<String> pagerList = findViewById(R.id.pager_list);
        pagerList.bindViewData(new Function2<String, PagerList.Holder, Unit>() {
            @Override
            public Unit invoke(String s, PagerList.Holder holder) {
                holder.setText(android.R.id.text1, s);
                return null;
            }
        })
                .layout(android.R.layout.simple_list_item_1)
                .data(strings)
                .finish();
    }

    @Override
    public void initData() {
        showLoading();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hideLoading();
            }
        }, 2000);
    }

    public void loading(View view) {
        initData();
    }

    public void error(View view) {
        showError();
    }

    public void empty(View view) {
        showEmpty();
    }

    public void go2State(View view) {
        startActivity(new Intent(this, StateActivity.class));
    }

    public void test(View view) {
        final StateDialog dialog = new StateDialog.Builder()
                .layout(R.layout.fragment_test)
                .fullContent()
                .transparentBg()
//                .postEvent(true)
//                .reloadListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Toast.makeText(MainActivity.this, "click", Toast.LENGTH_SHORT).show();
//                    }
//                })
                .builder();
        dialog.show(getSupportFragmentManager().beginTransaction(), "test");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dialog.dismiss();
            }
        }, 3000);
    }
}
